// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.window.application
import model.db.Db
import state.ApplicationWindowsState
import model.enums.ThemeType
import state.WindowType
import theme.EasyChatTheme
import ui.home.HomeWindow
import ui.login.loginWindows
import ui.more_setting.MoreSettingWindows
import ui.phone.PhoneWindow
import ui.search.SearchWindows

fun main() = application {

    Db.initDb()

    val applicationWindowsState = remember { ApplicationWindowsState() }
    val eChatTheme= remember { mutableStateOf(EasyChatTheme(ThemeType.Blue)) }

    for (window in applicationWindowsState.windowTypes) {
        when (window) {
            WindowType.LOGIN -> loginWindows(eChatTheme,applicationWindowsState) { applicationWindowsState.close(window) }
            WindowType.HOME -> HomeWindow(eChatTheme,applicationWindowsState) { applicationWindowsState.exit() }
            WindowType.Search -> SearchWindows(eChatTheme,applicationWindowsState) { applicationWindowsState.close(window) }
            WindowType.Setting -> MoreSettingWindows(eChatTheme,applicationWindowsState) { applicationWindowsState.close(window) }
            WindowType.Phone -> PhoneWindow(applicationWindowsState) { applicationWindowsState.close(window) }
        }
    }
}
